package com.lagou;

import com.lagou.bean.ConsumerComponent;
import com.lagou.bean.ConsumerRandom;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class AnnotationConsumerTPMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AnnotationConsumerMain.ConsumerConfiguration.class);
        context.start();
        ConsumerRandom service = context.getBean(ConsumerRandom.class);
        ExecutorService executorService =new ThreadPoolExecutor(100,500,1, TimeUnit.SECONDS,new LinkedBlockingDeque<>());
        for (int i = 0; i < 5000; i++) {
            executorService.execute(()->{
                service.methodA("methodA");
                service.methodB("methodB");
                service.methodC("methodC");
            });
            System.out.println(i);
        }

        executorService.shutdown();
         while (true){
             if (executorService.isTerminated()) {
                    break;
             }
         }
         Thread.sleep(200000);
    }




    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
